<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function(){
	var oTab=document.getElementById('tab1');
	var oldColor='';
	
	for(var i=0;i<oTab.tBodies[0].rows.length;i++)
	{
		oTab.tBodies[0].rows[i].onmouseover=function()
		{
			oldColor=this.style.background;
			this.style.background='red';
		}
		oTab.tBodies[0].rows[i].onmouseout=function()
		{
			this.style.background=oldColor;
		}
		
		if(i%2)
		{
			oTab.tBodies[0].rows[i].style.background='';
		}
		else
		{
			oTab.tBodies[0].rows[i].style.background='#CCC';
		}
	}
};
</script>
</head>

<body>
<table id="tab1" border="1" width="500">
	<thead>
    	<td>ID</td>
        <td>姓名</td>
        <td>年龄</td>
    </thead>
    <tbody>
    	<tr>
        	<td>1</td>
            <td>张三</td>
            <td>20</td>
        </tr>
        <tr>
        	<td>2</td>
            <td>李四</td>
            <td>24</td>
        </tr>
        <tr>
        	<td>3</td>
            <td>王五</td>
            <td>22</td>
        </tr>
        <tr>
        	<td>4</td>
            <td>刘六</td>
            <td>23</td>
        </tr>
        <tr>
        	<td>5</td>
            <td>张玮</td>
            <td>21</td>
        </tr>
    </tbody>
</table>
</body>
</html>
